home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
230_01
/
tests.bun
< prev
Wrap
Text File
|
1987-05-25
|
46KB
|
2,092 lines
: To unbundle, sh this file
echo unbundling Makefile 1>&2
cat >Makefile <<'End'
.SUFFIXES : .st .test
BINDIR = ../bin
FILES = Makefile in *.st *.out
.st.test:
$(BINDIR)/st -m $*.st <in | diff - $*.out
install:
echo Performing Self Checking Tests
-make basic.test
-make blocks.test
-make fork.test
-make new.test
-make super.test
-make copy.test
-make num.test
-make file.test
-make primes.test
-make collect.test
-make 4queen.test
echo The following produce cycles, thus have nonzero differences
-make phil.test
echo Differences in random numbers may change results in following
-make sim1.test
-make sim2.test
echo Finished Self Checking Tests
bundle:
bundle $(FILES) >../tests.bundle
# if the CURSES routines are available, and the form library has been
# built in the /prelude subdirectory (see Makefile there), the following
# executes the plane example
plane:
$(BINDIR)/st -m -g form plane.st <in
# if the PLOT(3) routines are available, and the pen library has been
# built in the /prelude subdirectory (see Makefile there), the following
# executes the pens exame
pen:
$(BINDIR)/st -m -g pen penshow.st <in
End
echo unbundling in 1>&2
cat >in <<'End'
Main new main
End
echo unbundling 4queen.st 1>&2
cat >4queen.st <<'End'
Class Queen
| myrow mycolumn neighbor boardsize |
[
build: aQueen col: aNumber size: brdmax
neighbor <- aQueen.
mycolumn <- aNumber.
myrow <- 1.
boardsize <- brdmax.
neighbor first.
^ self
| checkCol: colNumber row: rowNumber | cd |
(rowNumber = myrow) ifTrue: [ ^ false ].
cd <- colNumber - mycolumn.
((myrow + cd) = rowNumber) ifTrue: [ ^ false ].
((myrow - cd) = rowNumber) ifTrue: [ ^ false ].
(neighbor isNil) ifFalse:
[ ^ neighbor checkCol: colNumber row: rowNumber ].
^ true
| first
myrow <- 1.
^ self checkrow
| next
myrow <- myrow + 1.
^ self checkrow
| checkrow
(neighbor isNil) ifTrue: [^ myrow].
[myrow <= boardsize] whileTrue:
[(neighbor checkCol: mycolumn row: myrow)
ifTrue: [^ myrow]
ifFalse: [myrow <- myrow + 1] ].
((neighbor next) isNil) ifTrue: [^ nil].
^ self first
| printboard
(neighbor isNil) ifFalse: [ neighbor printboard].
('Col ', mycolumn asString , ' Row ' ,
myrow asString) print
]
Class Main
| lastq |
[
main | size |
size <- 4.
lastq <- nil.
(1 to: size) do: [:x |
lastq <- Queen new build: lastq col: x size: size ].
lastq first.
lastq printboard
]
End
echo unbundling 8queen.st 1>&2
cat >8queen.st <<'End'
Class Queen
| myrow mycolumn neighbor boardsize |
[
build: aQueen col: aNumber size: brdmax
neighbor <- aQueen.
mycolumn <- aNumber.
myrow <- 1.
boardsize <- brdmax.
neighbor first.
^ self
| checkCol: colNumber row: rowNumber | cd |
(rowNumber = myrow) ifTrue: [ ^ false ].
cd <- colNumber - mycolumn.
((myrow + cd) = rowNumber) ifTrue: [ ^ false ].
((myrow - cd) = rowNumber) ifTrue: [ ^ false ].
(neighbor isNil) ifFalse:
[ ^ neighbor checkCol: colNumber row: rowNumber ].
^ true
| first
myrow <- 1.
^ self checkrow
| next
myrow <- myrow + 1.
^ self checkrow
| checkrow
(neighbor isNil) ifTrue: [^ myrow].
[myrow <= boardsize] whileTrue:
[(neighbor checkCol: mycolumn row: myrow)
ifTrue: [^ myrow]
ifFalse: [myrow <- myrow + 1] ].
((neighbor next) isNil) ifTrue: [^ nil].
^ self first
| printboard
(neighbor isNil) ifFalse: [ neighbor printboard].
('Col ', mycolumn asString , ' Row ' ,
myrow asString) print
]
Class Main
| lastq |
[
main | size |
size <- 8.
lastq <- nil.
(1 to: size) do: [:x |
lastq <- Queen new build: lastq col: x size: size ].
lastq first.
lastq printboard
]
End
echo unbundling basic.st 1>&2
cat >basic.st <<'End'
Class Main
[
main
88 print.
3.14159 print.
'this is it' print.
#(this is also it) print.
88 respondsTo: #+ ; print.
Object respondsTo.
smalltalk at: 3 put: #(22 17).
(smalltalk at: 3) print.
Smalltalk respondsTo.
]
End
echo unbundling blocks.st 1>&2
cat >blocks.st <<'End'
Class Main
[
main
(2 < 3) ifTrue: ['correct-1' print].
((2 < 3) ifTrue: ['correct-2']) print.
[:x | x print] value: 'correct-3' .
((2 < 3) or: [3 < 4]) ifTrue: ['correct-4' print].
((2 > 3) or: [3 < 4]) ifTrue: ['correct-5' print].
((2 < 3) and: [3 < 4]) ifTrue: ['correct-6' print].
((2 > 3) and: [3 < 4]) ifFalse: ['correct-7' print].
self test1 print
|
test1
self test2: [^ 'correct-8'].
'should not print' print
|
test2: aBlock
self test3: aBlock.
'should not print' print
|
test3: bBlock
bBlock value.
'should not print' print
]
End
echo unbundling check.st 1>&2
cat >check.st <<'End'
Class CheckBook
| balance |
[
new
balance <- 0
|
+ amount
balance <- balance + amount.
^ balance
|
- amount
balance <- balance - amount.
^ balance
]
End
echo unbundling collect.st 1>&2
cat >collect.st <<'End'
Class Main
| i |
[
main
self test1.
self test2.
self test3
|
test1 | j |
(i <- 'example') print.
i size print.
i asArray print.
(i occurrencesOf: $e) print.
i asBag print.
(j <- i asSet) print.
j asString reversed print.
i asDictionary print.
(j <- i asList) print.
j addFirst: 2 / 3.
j addAllLast: (12.5 to: 15 by: 0.75).
j print.
j removeLast print.
(j , #($a 7) ) print.
(i reject: [:x | x isVowel] ) print.
(i copyWithout: $e) print.
i sort print.
(i sort: [:x :y | y < x]) print.
i keys print.
i values print.
(i atAll: (1 to: 7 by: 2) put: $x) print
|
test2 | j |
i <- (1 to: 6) asBag print.
i size print.
(i select: [:x | (x \\ 2) strictlyPositive] ) print.
(j <- (i collect: [:x | x \\ 3]) asSet ) print.
j size print
|
test3
('bead' at: 1 put: $r) print
]
End
echo unbundling cond.st 1>&2
cat >cond.st <<'End'
Class Main
[
main | i |
((2 < 3) ifTrue: ['correct']) print.
(2 < 3) ifTrue: ['correct' print ].
i <- 1.
[i < 3] whileTrue: [i <- i + 1].
(i >= 3) ifTrue: ['correct' print]
]
End
echo unbundling control.st 1>&2
cat >control.st <<'End'
"
control the values produced by a generator
"
Class ControlGenerator :Generator
| firstGenerator secondGenerator
currentFirst currentSecond
controlBlock computeBlock |
[
initA: fGen b: sGen control: aBlock compute: anotherBlock
firstGenerator <- fGen.
secondGenerator <- sGen.
controlBlock <- aBlock.
computeBlock <- anotherBlock
| first
currentFirst <- firstGenerator first.
currentSecond <- secondGenerator first.
(currentFirst isNil & currentSecond isNil) ifTrue: [^ nil].
^ self controlGeneratorNext
| next
^ self controlGeneratorNext
| controlGeneratorNext | control returnedValue